package org.u2ml.stack.db.h2;
import java.sql.SQLException;

import org.h2.tools.Server;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class H2DatabaseEngine {
	private Logger logger = LoggerFactory.getLogger(H2DatabaseEngine.class);
	
	// ports configuration, the defaults are the same as in H2 itself
	private int tcpPort = 9092;
	private int webPort = 8082;
	private int pgPort = 5435;

	public H2DatabaseEngine() {
	}
	
	public void start() throws SQLException {
		logger.info("starting h2 database");
		String[] args = new String[] {
				"-tcp", "-tcpPort", String.valueOf(tcpPort), 
				"-web", "-webPort", String.valueOf(webPort), 
				"-pg", "-pgPort", String.valueOf(pgPort), 
		};
		new Server().run(args); 
	}
	
	public void stop() {
	}

	public int getTcpPort() {
		return tcpPort;
	}

	public void setTcpPort(int tcpPort) {
		this.tcpPort = tcpPort;
	}

	public int getWebPort() {
		return webPort;
	}

	public void setWebPort(int webPort) {
		this.webPort = webPort;
	}

	public int getPgPort() {
		return pgPort;
	}

	public void setPgPort(int pgPort) {
		this.pgPort = pgPort;
	}
}